package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.dto.AccountPrivacy;
import com.example.entity.vo.request.PrivacySaveVo;
import com.example.mapper.AccountPrivacyMapper;
import com.example.service.AccountPrivacyService;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @Author: shenjianZ
 * @Date: 2024/4/27 下午4:23
 * @Description:
 */

@Service
public class AccountPrivacyServiceImpl extends ServiceImpl<AccountPrivacyMapper, AccountPrivacy> implements AccountPrivacyService {

    @Override
    public void savePrivacy(int id, PrivacySaveVo vo) {
        AccountPrivacy accountPrivacy = Optional.ofNullable(getById(id)).orElse(new AccountPrivacy(id));
        boolean status = vo.isStatus();
        switch (vo.getType()) {
            case "phone":
                accountPrivacy.setPhone(status);
                break;
            case "email":
                accountPrivacy.setEmail(status);
                break;
            case "qq":
                accountPrivacy.setQq(status);
                break;
            case "wx":
                accountPrivacy.setWx(status);
                break;
            case "gender":
                accountPrivacy.setGender(status);
                break;
        }
        this.saveOrUpdate(accountPrivacy);
    }

    @Override
    public AccountPrivacy accountPrivacy(int id) {
        return Optional.ofNullable(this.getById(id)).orElse(new AccountPrivacy(id));
    }
}
